<!--学生报名信息管理页面-->
<template>
    <div>
        <div style="display: flex;align-items: center;justify-content: center">
            <el-input style="width: 150px" placeholder="查询名称" v-model="title" clearable></el-input>
            <el-select style="width: 100px; margin: 0 10px" v-model="sign" placeholder="竞赛类型">
                <el-option
                        v-for="item in options"
                        :key="item"
                        :label="item"
                        :value="item">
                </el-option>
            </el-select>
            <el-select style="width: 150px; margin: 0 10px" v-model="teacher" placeholder="指导教师">
                <el-option
                        v-for="item in teachers"
                        :key="item"
                        :label="item"
                        :value="item">
                </el-option>
            </el-select>

            <el-button type="primary" style="margin-left: 10px" @click="load(1)">查询</el-button>
            <el-button type="info" @click="reset" plain>重置</el-button>
        </div>

        <el-table :data="tableData"
                  stripe
                  :header-cell-style="{ backgroundColor: 'aliceblue', color: '#666'}"
                  style="font-size: 14px; margin-top: 20px"
                  @selection-change="handleSelectionChange"
        >
            <el-table-column width="55" align="center"></el-table-column>
            <el-table-column prop="title" label="竞赛名称" align="center"></el-table-column>
            <el-table-column prop="sign" label="竞赛类型" align="center"></el-table-column>
            <el-table-column prop="username" label="参赛者" align="center"></el-table-column>
            <el-table-column prop="major" label="学部" align="center"></el-table-column>
            <el-table-column v-slot="scope" prop="audit" label="审核状态" align="center">
                <el-tag type="primary" style="font-size: 14px"
                        v-if="scope.row.audit === '待审核'">待审核</el-tag>
                <el-tag type="success" style="font-size: 14px"
                        v-if="scope.row.audit === '已通过'">已通过
                </el-tag>
                <el-tag type="warning" style="font-size: 14px"
                        v-if="scope.row.audit === '未通过'">未通过
                </el-tag>
            </el-table-column>
            <el-table-column prop="content" label="审核内容" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column v-slot="scope" prop="payfor" label="支付状态" align="center">
                <el-tag type="primary" style="font-size: 14px" v-if="scope.row.pay === '免费'">无需付费</el-tag>
                <el-tag type="warning" style="font-size: 14px"
                        v-if="scope.row.payfor === '待支付' && scope.row.pay === '付费'">待支付
                </el-tag>
                <el-tag type="success" style="font-size: 14px"
                        v-if="scope.row.payfor === '已支付' && scope.row.pay === '付费'">已支付
                </el-tag>
            </el-table-column>
            <el-table-column v-slot="scope" prop="grade" label="评分状态" align="center">
                <el-tag type="success" style="font-size: 14px"
                        v-if="scope.row.grade === '已评分'">已评分
                </el-tag>
                <el-tag type="warning" style="font-size: 14px"
                        v-if="scope.row.grade === '待评分'">待评分
                </el-tag>
            </el-table-column>
            <el-table-column label="操作" align="center" width="220">
                <template v-slot="scope" style="font-size: 14px">
                    <el-button style="padding: 6px" size="mini" type="success" plain
                               @click="$router.push('/enrollDetail?id=' + scope.row.id)">详情
                    </el-button>
                    <el-button style="padding: 6px" size="mini" plain type="primary"
                               v-if="scope.row.audit === '已通过' && scope.row.pay === '付费' && scope.row.payfor === '待支付'"
                               @click="pay(scope.row)">支付
                    </el-button>
                    <el-button style="padding: 6px" size="mini" type="danger" plain @click="del(scope.row.id)">撤回
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div style="margin: 10px 0; display: flex; align-items: center; justify-content: center">
            <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-size="pageSize"
                    layout="total, prev, pager, next"
                    :total="total">
            </el-pagination>
        </div>
    </div>

</template>

<script>

    export default {
        name: "Enroll",
        data() {
            return {
                tableData: [], //所有的数据
                pageNum: 1, //当前的页码
                pageSize: 6, //每页显示的个数
                title: '',
                sign: '',
                teacher: '',
                //竞赛类型
                options: [],
                //教师
                teachers: [],
                total: 0, //默认是0
                user: JSON.parse(localStorage.getItem("honey-user") || '{}'),//拿取个人用户信息
                content: '',
            }
        },
        created() {
            this.load()
        },
        methods: {
            pay(row) {
                window.open('http://localhost:9090/alipay/pay?id=' + row.id)
            },
            handleSelectionChange(rows) { //选中的数据 rows:当前选中的所有行数据
                this.ids = rows.map(v => v.id)
            },
            reset() {
                this.title = ''
                this.sign = ''
                this.teacher = ''
                this.load()
            },
            del(id) { //单个删除
                this.$confirm('确认删除？', '确认删除', {type: "warning"}).then(response => {
                    this.$request.delete('/enroll/delete/' + id).then(res => {
                        if (res.code === '200') { //操作成功
                            this.$message.success('操作成功')
                            this.load(1) //刷新表格数据
                        } else { //操作失败
                            this.$message.error(res.msg) //弹出错误信息
                        }
                    })
                }).catch(() => {
                })
            },
            load(pageNum) { //分页查询
                if (pageNum) {
                    this.pageNum = pageNum
                }
                this.$request.get('/enroll/selectByUserPage', {
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        title: this.title,
                        sign: this.sign,
                        teacher: this.teacher,
                    }
                }).then(res => {
                    this.tableData = res.data.records
                    console.log(this.tableData)
                    this.total = res.data.total
                })
                //接收竞赛类型值
                this.$request.get('/sign/selectAll').then(res => {
                    this.options = res.data
                })
                //接收教师值
                this.$request.get('/user/selectTeacher').then(res => {
                    this.teachers = res.data
                    console.log(this.teachers)
                })
            },
            handleCurrentChange(pageNum) {
                this.load(pageNum)
            },
        }
    }

</script>

<style>
    .el-tooltip__popper {
        max-width: 400px;
    }
</style>